package pe.edu.upc.dew.pharma.controller;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class BaseController
{
	private static final Log logger = LogFactory.getLog(BaseController.class);
	
	protected void printRequestAtributes(HttpServletRequest request)
	{
		@SuppressWarnings("rawtypes")
		Enumeration atribs = request.getAttributeNames();
		logger.debug("REQUEST - ATRIBUTOS:");
		if(logger.isDebugEnabled())
		{
			while(atribs.hasMoreElements())
			{
				logger.debug("  " + atribs.nextElement().toString() + " : " + request.getAttribute(atribs.nextElement().toString()));
			}
		}
	}
	
	protected void printRequestParameters(HttpServletRequest request)
	{
		@SuppressWarnings("rawtypes")
		Enumeration atribs = request.getParameterNames();
		logger.debug("REQUEST - PARAMETROS:");
		if(logger.isDebugEnabled())
		{
			while(atribs.hasMoreElements())
			{
				logger.debug("  " + atribs.nextElement().toString() + " : " + request.getAttribute(atribs.nextElement().toString()));
			}
		}
	}
	
	protected void printSessionAtributes(HttpServletRequest request)
	{
		HttpSession session = request.getSession(false);
		@SuppressWarnings("rawtypes")
		Enumeration atribs = session.getAttributeNames();
		logger.debug("SESSION - ATRIBUTOS:");
		if(logger.isDebugEnabled())
		{
			while(atribs.hasMoreElements())
			{
				logger.debug("  " + atribs.nextElement().toString() + " : " + session.getAttribute(atribs.nextElement().toString()));
			}
		}
	}
}
